<?php
session_start();//
include_once('conn.php');
$username='';
empty($_SESSION['username'])?$username=$_COOKIE['username']:$username=$_SESSION['username'];
//if ($_SESSION['username']!=null){
//    $username=$_SESSION['username'];
//}else{
//    $username=$_COOKIE['username'];
//}
$sql = "select * from `student_info` order by stu_id";
$result = mysqli_query($conn,$sql);
if (isset($username)&&$username='admin'){
?>
<html>
<head>
    <meta charset="utf-8">
    <title>学生管理系统</title>
    <script>
        function del(){
            if(!window.confirm("确定要删除吗？")){
                return false;
            }
        }
    </script>
    <script>
        function show(){
            var date = new Date(); //日期对象
            var now = "";
            now = date.getFullYear()+"年"; //读英文就行了
            now = now + (date.getMonth()+1)+"月"; //取月的时候取的是当前月-1如果想取当前月+1就可以了
            now = now + date.getDate()+"日";
            now = now + date.getHours()+"时";
            now = now + date.getMinutes()+"分";
            now = now + date.getSeconds()+"秒";
            document.getElementById("nowDiv").innerHTML = now; //div的html是now这个字符串
            setTimeout("show()",1000); //设置过1000毫秒就是1秒，调用show方法
        }
    </script>
</head>
<body onload="show()">
<h1>学生管理系统-首页</h1>
<h6><?php echo '北京时间：<div id="nowDiv"></div>'?></h6>
<h4><?php echo '欢迎你，'.$username?></h4>
<h5><a href="exit.php">登出</a></h5>
<table border="1" width="600">
    <tr>
        <th>学生编号</th>
        <th>学生姓名</th>
        <th>学生分数</th>
        <th>操作</th>
    </tr>
    <?php
    if(!mysqli_num_rows($result)) {//
        echo "<tr align='center'><td colspan='4'>暂无数据！</td></tr>";
    }else {
        while ($row = mysqli_fetch_assoc($result)) {
            ?>
            <tr align="center">
                <td><?php echo $row['stu_id'] ?></td>
                <td><?php echo $row['stu_name'] ?></td>
                <td><?php echo $row['stu_score'] ?></td>
                <td><a href="edit.php?stu_id=<?php echo $row['stu_id'] ?>">修改</a>|
                    <a href="delete.php?stu_id=<?php echo $row['stu_id'] ?>" onclick="return del();">删除</a></td>
            </tr>
            <?php
        }
    }
    ?>
</table>
<a href="add.php">添加学生</a>
</body>
</html>
<?php
}else{
    echo '您还没有登录，请先登录';
    echo '<a href="test.html">点击登录</a>';
}

